﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;

namespace LogicUniversity.clerks
{
    public partial class MaintainDepartment : System.Web.UI.Page
    {
        protected void Page_PreInit(Object sender, EventArgs e)
        {
            //(Session["Role"]
            if (Session["Role"] as string != "Clerk")
            {
                Response.Redirect("~/Login.aspx");
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DepartmentMaintain md = new DepartmentMaintain();
                List<Department> d = md.getDepartment();
                DataBind();
                fillDataGrid();
            }
        }
        public void fillDataGrid()
        {
            DepartmentMaintain md = new DepartmentMaintain();
            List<Department> d = md.getDepartment();
            GridView1.DataSource = d;
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddDepartment.aspx");
        }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            AddDepartment add = new AddDepartment();
            GridViewRow row = GridView1.SelectedRow;
            string dept_Code = row.Cells[1].Text.ToString();
            string dept_Name = row.Cells[2].Text.ToString();
            string contact_Name = row.Cells[3].Text.ToString();
            string tel = row.Cells[4].Text.ToString();
            string fax = row.Cells[5].Text.ToString();
            string head_Name = row.Cells[6].Text.ToString();
            string collection_Point = row.Cells[7].Text.ToString();
            string rep_Name = row.Cells[8].Text.ToString();
            Session["Dept_Code"] = dept_Code;
            Session["Dept_Name"] = dept_Name;
            Session["Contact_Name"] = contact_Name;
            Session["Tel_No"] = tel;
            Session["Fax_No"] = fax;
            Session["Head_Name"] = head_Name;
            Session["Collection_Point"] = collection_Point;
            Session["Rep_Name"] = rep_Name;

            Response.Redirect("UpdateDepartment.aspx");
        }
    }
}